from math import exp
count = 0
percentage = 0
totalpercentage = 0


# getData for Plot ----------------------------------------------

def PlotThePercentage (dist):
	for s in dist.keys():
		if (s == 1):
			PlotThePercentage1 (dist[s])

def PlotThePercentage1 (dist):
	for s in dist.keys():
		percent1 = 0
		percent2 = 0
		if (s == 'C'):
			#print s, ":", exp(dist[s]),
			percent1 = exp(dist[s])
			percentage = percent1 
		if (s == 'G'):
			#print s, ":", exp(dist[s])
			percent2 = exp(dist[s])
			percentage += percent2 

	global count
	global percentage
	global totalpercentage
	count += 1	
	totalpercentage += percentage
	print totalpercentage
	
	if (count == 10):
		average = 0
		average = totalpercentage / count	
		print "The average percentage of the last ", count, "results  are", average 
		count = 0
		percentage = 0
		totalpercentage = 0

def getCGPercents(hid_seq, hid, window = 20):
  s=""
  for i in range(len(hid_seq)):
    w = hid_seq[max(0, i-window/2):min(i+window/2, len(hid_seq)-1)]
    if len(w) == 0:
      continue
    import re
    if 1 in hid:
      s += str(i)+", "+str(float(len(re.findall("1", w)))/float(len(w)))+"\n"
    else:
      s += str(i)+", "+str(float(len(re.findall("I", w)))/float(len(w)))+"\n"
  return s
